import { Watermark } from "watermark-js-plus";
import { getConfig } from "@/api/system-config/systemWatermark";
let watermark = null;
export function setWatermark() {
  getConfig().then(({ data }) => {
    data.enable === "1" && createWatermark(data);
  });
}

function createWatermark(data) {
  let content = "";
  let checkList = data.contents.split(",");
  if (checkList.includes("name")) {
    content += data.userName;
  }
  if (checkList.includes("tel")) {
    content += `   ${data.tel}`;
  }
  if (checkList.includes("ip")) {
    content += `   ${data.ip}`;
  }
  destroyWatermark()
  watermark = new Watermark({
    parent: "#app",
    content,
    zIndex: 99999,
    globalAlpha: data.alpha,
    fontSize: "24px",
    fontColor: "#4986F5",
  });

  watermark.create();
}

export function destroyWatermark() {
  watermark && watermark.destroy();
}
